package org.pentaho.plugins.xchart;

import java.io.OutputStream;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import org.pentaho.platform.engine.services.solution.SimpleContentGenerator;
import org.pentaho.platform.util.messages.LocaleHelper;

public class XChartContentGenerator extends SimpleContentGenerator {

  @Override
  public void createContent(OutputStream out) throws Exception {
    try {
      StringBuilder html = new StringBuilder();
      html.append("<html>");
      html.append("<head>");
      html.append("<meta name='gwt:property' content='locale=en_UK'/>");
      html.append("<title>XChart Editor</title>");
      html.append("<script language=\"javascript\" src=\"/pentaho/content/xchart-res/xchart/xchart.nocache.js\"></script>");
      html.append("</head>");
      
      html.append("<body>");
      html.append("<img src=\"/pentaho/content/xchart-res/images/pentaho_logo.png\" />");
      html.append("<h1>XChart Editor canvas</h1>");
      html.append("<div id=\"gechodiv\"></div>");
      html.append("<iframe src=\"javascript:''\" id=\"__gwt_historyFrame\" style=\"width:0;height:0;border:0\"></iframe>");
      html.append("</body>");
      
      html.append("</html>");
      out.write(html.toString().getBytes(LocaleHelper.getSystemEncoding()));
      
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  @Override
  public String getMimeType() {
    return "text/html";
  }

  @Override
  public Log getLogger() {
    return LogFactory.getLog(XChartContentGenerator.class);
  }

}
